<?php
namespace  Aitels\Foundation\Scanner;


use Symfony\Component\Finder\Finder;

class Scanner
{
    protected  $handlers = [];
    protected $scanDirs=[];

    public function __construct($scanDirs)
    {
        $this->scanDirs=$scanDirs;
    }

    public  function registerHandler(\Closure $handler)
    {
        $this->handlers[] = $handler;
    }

    public function scan()
    {
        $finder = new Finder();
        $files = $finder->files()->in($this->scanDirs)->name('/.+.php$/');
        foreach ($files as $file)
            foreach ($this->handlers as $handler){
                $handler($file);
            }
    }
}